﻿using SimpleInjector;
using Sustainalytics.Claims;
using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.DataLayer.ConnectionStrings;
using Sustainalytics.Entities.ConnectionStrings;
using Sustainalytics.MongoDB.Extensions;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Http;

namespace Sustainalytics.GCCS.Service.Infrastructure
{
    public static class CompositionRoot
    {
        public static Container RegisterDependencies(HttpConfiguration config)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();
            container.RegisterWebApiControllers(config);

            container.RegisterRepositories();

            container.RegisterMisc();

            container.RegisterBussinessLogic();            

            container.Verify();
            return container;
        }

        private static void RegisterRepositories(this Container container)
        {
            container.Register(typeof(IClientDWGlobalCompactRepository), () => 
                ClientDWGlobalCompactRepository.GetInstance(MongoFactory.GetConnectionStrings().ClientDW)
            );
        }

        private static void RegisterBussinessLogic(this Container container)
        {
            container.Register(typeof(IGCOverallCompanySummaryExtendedManager), () => new GCOverallCompanySummaryExtendedManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
            container.Register(typeof(IGCOverallCompanySummaryManager), () => new GCOverallCompanySummaryManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
            container.Register(typeof(IGCPrincipleConclusionManager), () => new GCPrincipleConclusionManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
            container.Register(typeof(IGCPrincipleEventIndicatorManager), () => new GCPrincipleEventIndicatorManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
            container.Register(typeof(IGCPrincipleEventIndicatorImpactManager), () => new GCPrincipleEventIndicatorImpactManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
            container.Register(typeof(IGCPrincipleEventIndicatorManagementManager), () => new GCPrincipleEventIndicatorManagementManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
            container.Register(typeof(IGCPrincipleSummaryManager), () => new GCPrincipleSummaryManager(container.GetInstance<IClientDWGlobalCompactRepository>()));
        }

        public static void RegisterMisc(this Container container)
        {
            container.RegisterSingleton(typeof(IClaimsChecker), () => new ClaimsChecker());
        }
    }
}
